From: Keir Fraser Date: Tue, 31 Mar 2009 10:21:14 +0000 (+0100) Subject: x86: virt_to_mfn() fixes. X-Git-Tag: archive/raspbian/4.8.0-1+rpi1~1^2~13989^2~67 X-Git-Url: https://dgit.raspbian.org/%22http:/www.example.com/cgi/%22https:/%22bookmarks://%22Dat/%22http:/www.example.com/cgi/%22https:/%22bookmarks:/%22Dat?a=commitdiff_plain;h=da2c44502457ff12405934742363102bbc281602;p=xen.git x86: virt_to_mfn() fixes. Signed-off-by: Xiaowei Yang --- diff --git a/xen/common/page_alloc.c b/xen/common/page_alloc.c index 830e44cdb4..ab3445b44b 100644 --- a/xen/common/page_alloc.c +++ b/xen/common/page_alloc.c @@ -302,7 +302,8 @@ static unsigned long init_node_heap(int node, unsigned long mfn, (mfn + needed) <= (virt_to_mfn(DIRECTMAP_VIRT_END - 1) + 1) ) { _heap[node] = mfn_to_virt(mfn); - avail[node] = mfn_to_virt(mfn + needed) - sizeof(**avail) * NR_ZONES; + avail[node] = mfn_to_virt(mfn + needed - 1) + + PAGE_SIZE - sizeof(**avail) * NR_ZONES; } #endif else if ( get_order_from_bytes(sizeof(**_heap)) == diff --git a/xen/include/asm-x86/x86_32/page.h b/xen/include/asm-x86/x86_32/page.h index aef51f51af..648d96de87 100644 --- a/xen/include/asm-x86/x86_32/page.h +++ b/xen/include/asm-x86/x86_32/page.h @@ -27,9 +27,6 @@ #define __PAGE_OFFSET (0xFF000000) #define __XEN_VIRT_START __PAGE_OFFSET -#define virt_to_maddr(va) ((unsigned long)(va)-DIRECTMAP_VIRT_START) -#define maddr_to_virt(ma) ((void *)((unsigned long)(ma)+DIRECTMAP_VIRT_START)) - #define VADDR_BITS 32 #define VADDR_MASK (~0UL) @@ -44,6 +41,22 @@ #include #include +static inline unsigned long __virt_to_maddr(unsigned long va) +{ + ASSERT(va >= DIRECTMAP_VIRT_START && va < DIRECTMAP_VIRT_END); + return va - DIRECTMAP_VIRT_START; +} +#define virt_to_maddr(va) \ + (__virt_to_maddr((unsigned long)(va))) + +static inline void *__maddr_to_virt(unsigned long ma) +{ + ASSERT(ma < DIRECTMAP_VIRT_END - DIRECTMAP_VIRT_START); + return (void *)(ma + DIRECTMAP_VIRT_START); +} +#define maddr_to_virt(ma) \ + (__maddr_to_virt((unsigned long)(ma))) + /* read access (should only be used for debug printk's) */ typedef u64 intpte_t; #define PRIpte "016llx" diff --git a/xen/include/asm-x86/x86_64/page.h b/xen/include/asm-x86/x86_64/page.h index 8899fe777c..fcfb8eef57 100644 --- a/xen/include/asm-x86/x86_64/page.h +++ b/xen/include/asm-x86/x86_64/page.h @@ -46,8 +46,14 @@ static inline unsigned long __virt_to_maddr(unsigned long va) } #define virt_to_maddr(va) \ (__virt_to_maddr((unsigned long)(va))) + +static inline void *__maddr_to_virt(unsigned long ma) +{ + ASSERT(ma < DIRECTMAP_VIRT_END - DIRECTMAP_VIRT_START); + return (void *)(ma + DIRECTMAP_VIRT_START); +} #define maddr_to_virt(ma) \ - ((void *)((unsigned long)(ma)+DIRECTMAP_VIRT_START)) + (__maddr_to_virt((unsigned long)(ma))) /* read access (should only be used for debug printk's) */ typedef u64 intpte_t;